﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class SelectorNodeHandler : CompositeNodeHandler
{
    public override BehaviorNodeState HandleComposite(BehaviorEntity entity, MultiBranchNodeData node)
    {
        while (node.CurIndex < node.ChildNodes.Count && node.ChildNodes[node.CurIndex].CurNodeState == BehaviorNodeState.Running)
        {
            GetChildNodeHandler(node.ChildNodes[node.CurIndex].CurNodeType).ExcuteNode(entity, node.ChildNodes[node.CurIndex]);
            if (node.ChildNodes[node.CurIndex].CurNodeState == BehaviorNodeState.Success)
            {
                node.CurNodeState = BehaviorNodeState.Failure;
                break;
            }
        }
        node.CurNodeState = BehaviorNodeState.Success;
        return node.CurNodeState;
    }
}